﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <title>Update</title>
    <script src="../../Scripts/PageCreater/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="../../Scripts/PageCreater/Scripts/PageCreater.js" type="text/javascript"></script>
    <link href="../../Scripts/PageCreater/Css/Style.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/PageCreater/Calendar/WdatePicker.js" type="text/javascript"></script>
    <script src='@Url.Content("~/Scripts/zTree/js/jquery-1.4.4.min.js")' type="text/javascript"></script>
    <link href='@Url.Content("~/Scripts/zTree/css/zTreeStyle/zTreeStyle.css")' rel="stylesheet" type="text/css" />
    <script src='@Url.Content("~/Scripts/zTree/js/jquery.ztree.core-3.5.js")' type="text/javascript"></script>
    <script src='@Url.Content("~/Scripts/zTree/js/jquery.ztree.excheck-3.5.js")' type="text/javascript"></script>
    <script src='@Url.Content("~/Scripts/zTree/js/jquery.ztree.exedit-3.5.js")' type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajaxSetup({ cache: false });
            var courseID;
            var testPaperID;
            $.ajax({
                type: "GET",
                url: "/Test/GetTestByID",
                data: { id: getUrlPara() },
                dataType: "json",
                success: function (json) {
                    courseID = json.courseID;
                    testPaperID = json.testpaperID;
                    $("#txtDate").val(json.date);
                    if (json.isactive == "True") {
                        $("#sltSit").append("<option value='true' selected='selected'>激活</option><option value='false'>注销</option>");
                    } else {
                        $("#sltSit").append("<option value='true'>激活</option><option value='false' selected='selected'>注销</option>");
                    }
                    $.ajax({
                        type: "GET",
                        url: "/Test/GetCourse",
                        success: function (str) {
                            var arr = str.split('|');
                            for (var i = 0; i < arr.length; i++) {
                                var subArr = arr[i].split(',');
                                if (subArr[0] == courseID) {
                                    $("#sltCourse").append("<option value='" + subArr[0] + "' selected='selected'>" + subArr[1] + "</option>");
                                } else {
                                    $("#sltCourse").append("<option value='" + subArr[0] + "'>" + subArr[1] + "</option>");
                                }
                            }
                            $.ajax({
                                type: "GET",
                                url: "/Test/GetTestPaper",
                                data: { courseID: function () { return $("#sltCourse").val(); } },
                                success: function (str) {
                                    $("#sltTestPaper").remove();
                                    if (str != "") {
                                        var arr = str.split('|');
                                        $("#tdTestPaper").append("<select id='sltTestPaper'><option>———请选择———</option></select>");
                                        for (var i = 0; i < arr.length; i++) {
                                            var subArr = arr[i].split(',');
                                            if (subArr[i] != testPaperID) {
                                                $("#sltTestPaper").append("<option value='" + subArr[0] + "'>" + subArr[1] + "</option>");
                                            } else {
                                                $("#sltTestPaper").append("<option value='" + subArr[0] + "' selected='selected'>" + subArr[1] + "</option>");
                                            }
                                        }
                                    }
                                    else {
                                        $("#tdTestPaper").append("<select id='sltTestPaper'><option>暂无试卷</option></select>");
                                    }
                                }
                            });
                        }
                    });
                }
            });
            $.fn.zTree.init($("#Tree"), setting, zNodes);
        })
        var zNodes = [];
        var setting = {
            async: {
                enable: true,
                url: "/Test/GetClassByTestPaper",
                type: "Get",
                dataType: "json",
                otherParam: { "id": getUrlPara() }
            },
            check: {
                enable: true
            },
            callback: {
                onAsyncSuccess: function (event, treeId, treeNode, msg) {
                },
                onAsyncError: function (event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
                    debugger;
                }
            }
        };
        function GetCourseSelect() {
            $.ajax({
                type: "GET",
                url: "/Test/GetCourse",
                success: function (str) {
                    var arr = str.split('|');
                    for (var i = 0; i < arr.length; i++) {
                        var subArr = arr[i].split(',');
                        $("#sltCourse").append("<option value='" + subArr[0] + "'>" + subArr[1] + "</option>");
                    }
                }
            });
        }
        function TestPaperOnclick() {
            if ($("#sltCourse").val() == "0") {
                alert("请先选择课程！");
            }
        }
        function GetTestPaperSelect() {
            $.ajax({
                type: "GET",
                url: "/Test/GetTestPaper",
                data: { courseID: function () { return $("#sltCourse").val(); } },
                success: function (str) {
                    $("#sltTestPaper").remove();
                    if (str != "") {
                        var arr = str.split('|');
                        $("#tdTestPaper").append("<select id='sltTestPaper'><option>———请选择———</option></select>");
                        for (var i = 0; i < arr.length; i++) {
                            var subArr = arr[i].split(',');
                            $("#sltTestPaper").append("<option value='" + subArr[0] + "'>" + subArr[1] + "</option>");
                        }
                    }
                    else {
                        $("#tdTestPaper").append("<select id='sltTestPaper'><option>暂无试卷</option></select>");
                    }
                }
            });
        }
        function SubmitPage() {
            var nodes = $.fn.zTree.getZTreeObj("Tree").getCheckedNodes(true);
            var selectIDs = "";
            for (var i = 0; i < nodes.length; i++) {
                selectIDs += nodes[i].id + ",";
            }
            selectIDs = selectIDs.substr(0, selectIDs.length - 1);
            $.ajax({
                type: "Post",
                url: "/Test/Update",
                data: { selectIDs: selectIDs, testID: getUrlPara(), courseID: $("#sltCourse").val(), date: $("#txtDate").val(), testpaper: $("#sltTestPaper").val(), IsActive: $("#sltSit").val() },
                success: function () {
                    alert("修改成功！");
                    window.location = "/Test/Index";
                }
            });
        }
    </script>
</head>
<body>
    <div class="Content">
        <p>
            @Html.ActionLink("返回列表", "Index")
        </p>
        <form id="Info" method="post">
        <fieldset>
            <legend>请输入基本信息</legend>
            <div id="divContent">
                <table>
                    <tr>
                        <td>
                            请选择课程：
                        </td>
                        <td>
                            <select id="sltCourse" onchange="GetTestPaperSelect()">
                                <option value="0">———请选择———</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            请选择考试时间：
                        </td>
                        <td>
                            <input id="txtDate" type="text" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            请选择试卷：
                        </td>
                        <td id="tdTestPaper">
                            <select id="sltTestPaper" onclick="TestPaperOnclick()">
                                <option>———请选择———</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            请选择状态：
                        </td>
                        <td>
                            <select id="sltSit">
                                <option>———请选择———</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            请选择班级：
                        </td>
                        <td>
                            <ul id="Tree" class="ztree">
                            </ul>
                        </td>
                    </tr>
                </table>
            </div>
        </fieldset>
        </form>
        <p>
            <input id="btnSubmit" type="button" value="保存" class="btn3" onclick="SubmitPage()" /></p>
    </div>
</body>
</html>
